package com.davidhigenbottam.HeatMap.data;

import java.util.ArrayList;
import java.util.List;

import com.davidhigenbottam.HeatMap.shared.Institution;
import com.davidhigenbottam.HeatMap.shared.Query;
import com.davidhigenbottam.HeatMap.shared.Result;

public class InstitutionData extends Data {
	public ArrayList<Institution> institutions= new ArrayList<Institution>();
	boolean maxValSet=false;
	boolean minValSet=false;
	double maxVal= -1.0d;
	double minVal= -1.0d;

	public InstitutionData(Query q){
		super(q);
	}

	public void addInstitution(Institution i) {
		
		//only geocoded institutions effect max and min values
		if(i.isGeocoded()){
			if(!maxValSet){
				maxVal= i.getVal();
				maxValSet=true;
			}
			else if(i.getVal()>maxVal) {
				maxVal= i.getVal();
			}
			
			if(!minValSet){
				minVal= i.getVal();
				minValSet=true;
			}
			else if(i.getVal()<minVal) {
				minVal= i.getVal();
			}
		}
		
		institutions.add(i);
		
	}
	
	
	
	
	
	public ArrayList<Institution> getInstitutions() {
		return institutions;
	}

	public void setInstitutions(ArrayList<Institution> institutions) {
		this.institutions = institutions;
	}

	public Double getIconScale(Institution i) {
		if(!minValSet || !maxValSet)
			throw new RuntimeException("min value and/or max value not set for InstitutionData");
		
		//find scale between 1 and 4
		return (((i.getVal()-minVal)/(maxVal-minVal))*3)+1;

	}
	public List<Institution> getList() {
		return institutions;
	}
	
	public List<Result> getResultsList() {
		List<Result> list = new ArrayList<Result>(institutions);
		return list;
	}

	public double getMaxVal() {
		return maxVal;
	}

	public void setMaxVal(double maxVal) {
		this.maxVal = maxVal;
	}

	public double getMinVal() {
		return minVal;
	}

	public void setMinVal(double minVal) {
		this.minVal = minVal;
	}
	
	
}
